#pragma once
#ifdef WIN32
#include <windows.h>
#endif
#ifdef MACX_DEV
#include <gl.h>
#include <glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

#include <QColor>
#include "geometryrenderplugin.h"

namespace PBVP {
	class GeometryDataNode;
	/// Default OpenGL Geometry Renderer
	class OpenGLRenderer : public QObject, public GeometryRenderPlugin
	{
		Q_OBJECT
	public:
		typedef enum {
			OGL_SMOOTH = 0,
			OGL_FLAT
		} ShadingMode;

		/// Constructor
		OpenGLRenderer();
		/// Destructor
		~OpenGLRenderer();

		/// Virtual functions inherited from Plugin
		virtual void initialize(MainInterface* mainInterface /* = NULL */);

		virtual QString name() const {
			return QString("OGL Renderer");
		}

		virtual QString description() const {
			return QString("Default OpenGL Geometry Renderer");
		};

		///
		virtual void setDataNode(DataNode *pDataNode);
		/// Virtural function from RenderPlugin
		virtual RenderPlugin* clone();
		///
		virtual bool initRender();
		///
		virtual bool isSupported(DataInterface *pData) const;
		///
		virtual void begin();
		///
		virtual void end();
		///
		virtual void render(DataNode* pData);
		///
		virtual void reset();
		///
		virtual QWidget* getRenderControl() const;

		//////////////////////////////////////////////////////////////////////////
		/// properties
		bool isWireFrame() const {
			return m_WireFrame;
		}
		void setWireFrame(bool wf) {
			m_WireFrame = wf;
			updateView();
		}
		GLenum shadingMode() const {
			return m_Shading;
		}
		void setShadingMode(GLenum shading) {
			m_Shading = shading;
			// emit rendererChanged();
			updateView();
		}
	signals:
		void rendererChanged();

	public slots:
		void updateView();
		///
		void setVisible(int state);
		///
		void setColor(const QColor& color);
		///
		void setTransparency(int alpha);
		///
		void showBBox(int state);
	protected:
		friend class OpenGLRenderControl;

		bool m_WireFrame;
		GLenum m_Shading;

		// Color for rendering the surface
		QColor m_Color;
		bool m_Visible;
		bool m_ShowBBox;

		GeometryDataNode *m_pGeoNode;
		OpenGLRenderControl *m_pControl;
	};
}
